<%@ taglib prefix="p" uri="/WEB-INF/tld/privilege.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%> 
<%response.setHeader("cache-control","public"); %>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>个人费用列表</title>
  <base href="<%=basePath%>"/>
  <%@ include file="../../list_include.jsp"%>
  
  <style type="text/css"> 
	fieldset,table,tr,td {margin:0; padding:0;}
	td {padding:0 5px 0 10px;}
	form label {font-weight:bold;}
	#actionTable {margin:5px 0;}
	table{border-collapse: collapse;}
  </style>

  <script type="text/javascript">
	$(document).ready(function() { 
       	$("#actionTable").tablesorter({theme:'green', widgets:['zebra'],
       		headers:{0:{sorter:false},
       			1:{sorter:false},
       			2:{sorter:false},
       			3:{sorter:false},
       			4:{sorter:false},
       			5:{sorter:false},
       			6:{sorter:false},
       			7:{sorter:false}}});
       	
       	$("#btn_pageUp").click(function(){
			var curPage = $("#curPage").val();
			$("#curPage").val(parseInt(curPage) - 1);
			$("#actionForm").submit();
       	});
       	
       	$("#btn_pageDown").click(function(){
       		var curPage = $("#curPage").val();
			$("#curPage").val(parseInt(curPage) + 1);
			$("#actionForm").submit();
       	});

        $("#btn_insert").click(function(){
            var queryString = $("#actionForm").formSerialize();
            queryString = encodeURIComponent(queryString);
            location.href = "<%=basePath%>pjcost/cost/userinsert.do?qs=" + queryString;
        });
        
        $("#btn_search").click(function(){
            $("#curPage").val(1);
            $("#actionForm").submit();
        });

        $("#btn_change").click(function(){
            var page = parseInt($("#selectPage").val());
            var curPage = parseInt($("#curPage").val());
            if(curPage == page) return;
            $("#curPage").val(parseInt(page));
            $("#actionForm").submit();
        });
        
        $.ajaxSetup ({ cache:false });
	});  
	
    function edit(id){
        var queryString = $("#actionForm").formSerialize();
        queryString = encodeURIComponent(queryString);
        location.href = "<%=basePath%>pjcost/cost/usermodify.do?id=" + id + "&qs=" + queryString;
    }
	
	function del(id) {
		if(confirm("确定删除该条记录？") != 1) return;
		
		$.get("pjcost/cost/delete.do", {id:id}, function(data) {
			var result = $.parseJSON(data);
			if(result.code == 1) {
				alert("删除成功!");
				$("#btn_search").click();
			} else {
				alert(result.message);
			}
		});
	}
  </script>
 </head>

 <body>
  <div>
    <fieldset>
      <legend>查询条件：</legend>
      <form id="actionForm" method="post" action="pjcost/cost/userlist.do">
        <table>
          <tr>
            <td><label for="province">省份</label></td>
            <td>
            	<select id="selectprovince" name="selectprovince" style="width:120px;">
            	   <option value="" style="color:red;">选择省份</option>
                   <c:forEach items="${provinces}" var="entry" varStatus="status">
                   		<option value="${entry.key }" <c:if test="${entry.key == selectprovince }">selected ="true"</c:if>>
                   		${entry.value }
                   		</option>
                   </c:forEach>
              	</select>             	
            </td>
            <td><label for="status">状态</label></td>
            <td>
            	<select id="status" name="status" style="width:120px;">
            		<option value="" style="color:red;">选择状态</option>
            		<option value="0" style="background:#f3ff71;" <c:if test="${status == 0 }">selected="true"</c:if>>已提交</option>
            		<option value="1" style="background:#97fa92;" <c:if test="${status == 1 }"> selected="true" </c:if>>审核中</option>
            		<option value="2" style="background:#fa9292;" <c:if test="${status == 2 }"> selected="true" </c:if>>已拒绝</option>
            		<option value="3" style="background:#5F9EA0;" <c:if test="${status == 3 }"> selected="true" </c:if>>结项中</option>
            		<option value="4" style="background:#87CEEB ;" <c:if test="${status == 4 }"> selected="true" </c:if>>归档中</option>
            		<option value="5" style="background:#FFEBCD ;" <c:if test="${status == 5 }"> selected="true" </c:if>>已归档</option>
            	</select>
            </td>
            <td><label for="sortinfo">排序</label></td>
            <td>
            	<select id="sortinfo" name="sortinfo" style="width:120px;">
            		<option style="color:red;" value="">选择排序</option>
            		<option value="0" <c:if test="${sortinfo == 0 }">selected="true"</c:if>>申请日期</option>
            		<option value="1" <c:if test="${sortinfo == 1 }">selected="true"</c:if>>最新回复日期</option>
            	</select>
            </td>
            <td><input type="submit" id="btn_search" name="btn_search" value="查询" style="width:80px;" /></td>
          </tr>
        </table>
        <input type="hidden" name="curPage" id="curPage" value="${curPage}" />
      </form>
    </fieldset>
  </div>
  
  <div>
  	<table id="actionTable" class="tablesorter">
	  <thead> 
	    <tr> 
	      <th width="5%">省份</th>
	      <th width="10%">申请人</th>
	      <th width="15%">申请日期</th> 
	      <th width="15%">最新回复日期</th>
	      <th width="20%">申请事由</th> 
	      <th width="9%">预算总额</th> 
	      <th width="8%">实际总额</th> 
 		  <th width="5%">状态</th>
	      <th width="8%">操作</th>
 	    </tr> 
	  </thead>
	  <tbody>
	 	<c:forEach items="${costList}" var="cost" varStatus="status">
	  	<tr>
	  	  <td style="word-wrap: break-word; word-break:break-all;">${provinces[cost.province] }</td>
	  	  <td style="word-wrap: break-word; word-break:break-all;">${recordsMap[cost.applyUser] }</td>
	  	  <td style="word-wrap: break-word; word-break:break-all;">${cost.applyTime }</td>
	  	  <td style="word-wrap: break-word; word-break:break-all;">${replyMap[cost.id] }</td>
	  	  <td style="word-wrap: break-word; word-break:break-all;">${cost.applyReason }</td>
	  	  <td style="word-wrap: break-word; word-break:break-all;"><fmt:formatNumber type="number" value="${cost.expectCost }" /> </td>
	  	  <td style="word-wrap: break-word; word-break:break-all;"><fmt:formatNumber type="number" value="${cost.actualCost }" /></td>
	  	  <c:choose>
	  	  	<c:when test="${cost.status == 0}">
	  	  		<td style="background:#f3ff71;">已提交</td>
	  	  	</c:when>
	  	  	<c:when test="${cost.status == 1}">
	  	  		<td style="background:#97fa92;">审核中</td>
		  	</c:when>
		  	<c:when test="${cost.status == 2 }">
		  		<td style="background:#fa9292;">已拒绝</td>
		  	</c:when>
		  	<c:when test="${cost.status == 3 }">
		  		<td style="background:#5F9EA0;">结项中</td>
		  	</c:when>
		  	<c:when test="${cost.status == 4 }">
		  		<td style="background:#87CEEB ;">归档中</td>
		  	</c:when>
		  	<c:otherwise>
		  	  	<td style="background:#FFEBCD ;">已归档</td>
		  	</c:otherwise>
	  	  </c:choose>
	  	  <td>
	  	  	<p:chkPri actionUrl="pjcost/cost/usermodify.do?id=${cost.id}"><a href=# onclick="javascript:edit('${cost.id}'); return false;">修改</a></p:chkPri>
	  	  	<p:chkPri actionUrl="pjcost/cost/delete.do?id=${cost.id}"><a href=# onclick="javascript:del('${cost.id}'); return false;">删除</a></p:chkPri>
	  	  </td>
	  	</tr>
	  	</c:forEach>
	  </tbody>
  	</table>
  </div>

  <div>
      <div style="float:left;">
        <p:chkPri actionUrl="pjcost/cost/userinsert.do"><input id="btn_insert" type="button" value="新增" /></p:chkPri>
      </div>

      <div style="text-align:right;">
        <c:if test="${curPage <= 1}"><input type="button" disabled="disabled" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${curPage > 1}"><input type="button" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${curPage >= totalPage}"><input type="button" id="btn_pageDown" disabled="disabled" value="下一页"/></c:if>
        <c:if test="${curPage < totalPage}"><input type="button" id="btn_pageDown" value="下一页"/></c:if>
        共${totalPage}页/共${totalRecords}条
        <select id="selectPage" style="width: auto;">
            <c:forEach var="i" begin="1" end="${totalPage}">
                <option id="${i}" <c:if test="${i == curPage}">selected="selected"</c:if>>${i}</option>
            </c:forEach>
        </select>
        <input id="btn_change" type="button" value="转至" />
      </div>
  </div>
 </body>
</html>

